home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_075 / dum2 / src / wbstart.mod < prev   
Text File  |  1992-05-06  |  3KB  |  108 lines

  1. (* Used in DuM2.mod to allow icon startup - thanks Richie !
  2.     FOR SOME REASON MY COMPILER DOESN'T LIKE AMIGAX.sym
  3.     and freezes every time I import ExecBase, so I kludged it
  4.  *)
  5.  
  6. (*
  7.  
  8.         This module determines if a task is running from
  9.         Workbench. If so, a procedure is provided to exit
  10.         properly without loosing memory.
  11.  
  12.         Created: 10/27/86 by Richie Bielak
  13.  
  14.         Modified:
  15.  
  16.         11/29/86 by Richie Bielak
  17.         Changed to use fixed "FindTask". The new "FindTask" was
  18.         kindly provided by TDI. However, I still don't understand
  19.         why the new one works, and the old one doesn't. The code
  20.         is nearly the same!
  21.  
  22.         Copyright (c) 1986 by Richie Bielak.
  23.  
  24.         This program may be freely copied, but please leave
  25.         my name in. Thanks. Richie.
  26.  
  27. *)
  28. IMPLEMENTATION MODULE WBStart;
  29.  
  30.   FROM SYSTEM               IMPORT  ADDRESS,NULL,ADR,CODE,SETREG,REGISTER;
  31.   FROM DOSExtensions        IMPORT  ProcessPtr;
  32.   FROM Ports                IMPORT  WaitPort, GetMsg, ReplyMsg;
  33.   FROM Interrupts           IMPORT  Forbid;
  34.   FROM DOSLibrary           IMPORT  DOSBase;
  35.   FROM Libraries            IMPORT  CloseLibrary;
  36. (*  FROM AMIGAX               IMPORT  ExecBase;
  37.   *)
  38.  
  39.  
  40.   (* +++++++++++++ NEW FIND TASK ++++++++++ *)
  41.  
  42.   CONST
  43.     D0 = 0; A1 = 9; A6 = 14;
  44.     JSRA6 = 4EAEH; SAVEA6 = 2F0EH; RESTOREA6 = 2C5FH;
  45.     FindTaskVec = -30-264;
  46.   VAR
  47.     ExecBase[4] : ADDRESS;
  48.   (* Tasks.FindTask has a bug.  Use this instead *)
  49.   PROCEDURE FindTask(name: ADDRESS): ADDRESS;
  50.     (* find a task with a given name, or find oneself. *)
  51.   BEGIN
  52.     CODE(SAVEA6);
  53.     SETREG(A1, name);
  54.     SETREG(A6,ExecBase);
  55.     CODE(JSRA6,FindTaskVec);
  56.     CODE(RESTOREA6);
  57.     RETURN REGISTER(D0);
  58.   END FindTask;
  59.  
  60.   (* ++++++++++++++++++++++++++++++++++++++++++ *)
  61.  
  62.   VAR
  63.     WBStartUpMsg : ADDRESS;
  64.  
  65.   (* Get WB Startup message - this procedure will return
  66.     NULL if the program is running from CLI.
  67.   *)
  68.   PROCEDURE GetWBStartUpMsg () : ADDRESS;
  69.     VAR
  70.       ThisProcess : ProcessPtr;
  71.     BEGIN
  72.       WBStartUpMsg := NULL;
  73.       (* Get ID of our task *)
  74.       (* Task record is imbedded in the Process record *)
  75.       ThisProcess := FindTask(0);
  76.  
  77.       (* See if we are running from CLI *)
  78.       IF ThisProcess^.prCLI <> 0 THEN
  79.         RETURN NULL
  80.       (* OK we're running from WB, get our startup msg *)
  81.       ELSE
  82.         WITH ThisProcess^ DO
  83.           (* Wait for the message, and remove it from the port *)
  84.           WBStartUpMsg := WaitPort (ADR(prMsgPort));
  85.           WBStartUpMsg := GetMsg (ADR(prMsgPort));
  86.           RETURN (WBStartUpMsg)
  87.         END;
  88.       END;
  89.     END GetWBStartUpMsg;
  90.  
  91.   (* Call to this procedure returns the startup message.
  92.      Call this procedure just before exiting your program.
  93.   *)
  94.   PROCEDURE ReturnWBStartUpMsg ();
  95.     BEGIN
  96.       IF WBStartUpMsg <> NULL THEN
  97.         (* Close DOS Library, if it's still open *)
  98.         IF DOSBase <> NULL THEN
  99.           CloseLibrary (DOSBase)
  100.         END;
  101.         Forbid ();
  102.         ReplyMsg (WBStartUpMsg);
  103.       END;
  104.     END ReturnWBStartUpMsg;
  105.  
  106. BEGIN
  107. END WBStart.
  108.